﻿using BangleAbp.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;

namespace BangleAbp.Permissions
{
    public class BangleAbpPermissionDefinitionProvider : PermissionDefinitionProvider
    {
        public override void Define(IPermissionDefinitionContext context)
        {
            var myGroup = context.AddGroup(BangleAbpPermissions.GroupName);

            //Define your own permissions here. Example:
            //myGroup.AddPermission(BangleAbpPermissions.MyPermission1, L("Permission:MyPermission1"));

            //myGroup.AddPermission(BangleAbpPermissions.Product, L("Menu:Product"));

            #region AbpIdentity
            var productsGroup = context.AddGroup(BangleAbpPermissions.ProductsGroupName, L("Menu:Products"));
            if (productsGroup != null)
            {
                var productTypePermission = productsGroup.AddPermission(BangleAbpPermissions.ProductType, L("Menu:ProductType"));
                productTypePermission.AddChild(BangleAbpPermissions.ProductTypeCreate, L("CreateProductType"));
                productTypePermission.AddChild(BangleAbpPermissions.ProductTypeUpdate, L("EditProductType"));
                productTypePermission.AddChild(BangleAbpPermissions.ProductTypeDelete, L("DeleteProductType"));


                var productPermission = productsGroup.AddPermission(BangleAbpPermissions.Product, L("Menu:Product"));
                productPermission.AddChild(BangleAbpPermissions.ProductCreate, L("CreateProduct"));
                productPermission.AddChild(BangleAbpPermissions.ProductUpdate, L("EditProduct"));
                productPermission.AddChild(BangleAbpPermissions.ProductDelete, L("DeleteProduct"));
            }
            #endregion

        }

        private static LocalizableString L(string name)
        {
            return LocalizableString.Create<BangleAbpResource>(name);
        }
    }
}
